package test_achieve;

import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.concurrent.TimeUnit;

/**
 * Created by chenkuo on 2017/7/3.
 */
public class Feature8 {


    @Given("^这是另外个feature$")
    public void 这是另外个feature() throws Throwable {
        System.out.println("这是另外一个feature");
        Thread.sleep(500);
    }

    @Given("^这是第二个场景失败$")
    public void 这是第二个场景失败() throws Throwable {
        boolean btn = false;
        Assert.assertEquals(true,btn);
    }
    @Given("^打开浏览器1$")
    public void openBrowser1() throws InterruptedException, UnknownHostException {
            System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
            Constant.driverWeb = new ChromeDriver();
//            zoomChrome();
        Constant.driverWeb.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        }

    @Given("^打开浏览器2$")
    public void openBrowser2() throws InterruptedException, UnknownHostException {
        System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
        Constant.driverWebb = new ChromeDriver();
//        zoomChrome();
        Constant.driverWebb.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
    }

    @Given("^打开浏览器3$")
    public void openBrowser3() throws InterruptedException, UnknownHostException {
        System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
        Constant.driverWebc = new ChromeDriver();
//        zoomChrome();
        Constant.driverWebc.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
    }




    private void zoomChrome() {
        final JavascriptExecutor js = (JavascriptExecutor) Constant.driverWeb;
        js.executeScript("window.open('','testwindow','width=2400,height=2048')");
        Constant.driverWebc.close();
        Constant.driverWebc.switchTo().window("testwindow");
//        js.executeScript("window.moveTo(0,0);");
//        js.executeScript("window.resizeTo(1400,1024);");
    }

    @Given("^w已登录并进入在线下单界面：(.+)$")
    public   void wLogInEnterInterface(String username) throws UnknownHostException {
        wLoging(username);
//        Constant.driverWeb.findElement(By.linkText("在线下单")).click();
    }

    @Given("^w用户已登录：(.+)$")
    public   void wLoging(String username) throws UnknownHostException {
        Constant.driverWeb.get("http://www.sf.bingex.com/user/logout");
        Constant.driverWeb.findElement(By.id("captchaCode2_link")).click();
        System.out.println("用户手机号："+username);
        Constant.driverWeb.findElement(By.xpath("//input[@id='username']")).sendKeys(username);
        Constant.driverWeb.findElement(By.xpath("//input[@id='password']")).sendKeys("123456");
        Constant.driverWeb.findElements(By.className("form-actions")).get(1).click();
    }


    @Given("^关闭浏览器$")
    public void 关闭浏览器() throws Throwable {
//        Constant.driverWeb.quit();
    }
}
